package com.buyouchina.bean.product;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.buyouchina.bean.area.Province;
import com.buyouchina.bean.privilege.User;

/**
 * 直销店
 * */
@Entity
@Table(name = "outlets")
public class Outlets {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer id;

	private String name;

	// 创建时间
	private Date date;

	// 联系电话
	private String telphone;
	//	备用电话
	private String back_telphone;
	//	备用电话2
	private String back_tel2;
	// 传真
	private String fax;
	// 地址
	private String address;
	// 邮政编码
	private String postCode;
	// 备注
	private String remark;
	//	邮件
	private String email;
	//	网址
	private String site;
	//QQ
	private String qq;

	// 类型(销售单&发货单)
	@Enumerated(EnumType.STRING)
	@Column(length = 10)
	private OutletsType type;

	// 店长
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "manager_userid")
	private User manager;
	
	// 店长
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "proxyManager_userid")
	private User proxyManager;

	// 店铺创建人
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "create_userid")
	private User creater;

	// 店铺所属地区
	@ManyToOne(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "province_id")
	private Province province;

	// 店铺里的人员
	@ManyToMany(fetch = FetchType.EAGER, cascade = { CascadeType.REFRESH })
	@JoinTable(name = "user_outlets", joinColumns = { @JoinColumn(name = "outlets_id", referencedColumnName = "id", nullable = true) }, inverseJoinColumns = { @JoinColumn(name = "user_id", referencedColumnName = "id", nullable = true) })
	private Set<User> users = new HashSet<User>();
	
	@OneToMany(mappedBy="outlets")
	private Set<Product> products=new HashSet<Product>();

	// 枚举店铺类型
	public enum OutletsType {
		BASE {
			public String getName() {
				return "总部";
			}
		},
		STORE {
			public String getName() {
				return "直销店";
			}
		},STORELESS {
			public String getName() {
				return "直销店下小店";
			}
		},
		WAREHOUSE {
			public String getName() {
				return "仓库";
			}
		};
		public abstract String getName();
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Province getProvince() {
		return province;
	}

	public void setProvince(Province province) {
		this.province = province;
	}

	public User getCreater() {
		return creater;
	}

	public void setCreater(User creater) {
		this.creater = creater;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public User getManager() {
		return manager;
	}

	public void setManager(User manager) {
		this.manager = manager;
	}

	public String getTelphone() {
		return telphone;
	}

	public void setTelphone(String telphone) {
		this.telphone = telphone;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Set<User> getUsers() {
		return users;
	}

	public void setUsers(Set<User> users) {
		this.users = users;
	}

	public OutletsType getType() {
		return type;
	}

	public void setType(OutletsType type) {
		this.type = type;
	}

	public Set<Product> getProducts() {
		return products;
	}

	public void setProducts(Set<Product> products) {
		this.products = products;
	}

	public String getBack_telphone() {
		return back_telphone;
	}

	public void setBack_telphone(String backTelphone) {
		back_telphone = backTelphone;
	}

	public String getBack_tel2() {
		return back_tel2;
	}

	public void setBack_tel2(String backTel2) {
		back_tel2 = backTel2;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getSite() {
		return site;
	}

	public void setSite(String site) {
		this.site = site;
	}

	public String getQq() {
		return qq;
	}

	public void setQq(String qq) {
		this.qq = qq;
	}

	public User getProxyManager() {
		return proxyManager;
	}

	public void setProxyManager(User proxyManager) {
		this.proxyManager = proxyManager;
	}

}
